package models

import "gorm.io/gorm"

// 订单表
type Order struct {
	gorm.Model
	UserId      int64   `gorm:"type:int(11);comment:用户id"`
	OrderNo     string  `gorm:"type:varchar(50);comment:订单编号"`
	OrderPrice  float64 `gorm:"type:decimal(10,2);default:0.00;comment:订单金额"`
	OrderStatus int64   `gorm:"type:int(11);default:0;comment:订单状态: 0未支付 1已支付"`
	OrderPay    int64   `gorm:"type:int(11);default:0;comment:支付方式: 0微信 2支付宝"`
}

// 订单商品表
type OrderGood struct {
	gorm.Model
	OrderId    int64  `gorm:"type:int(11);comment:订单id"`
	GoodsId    int64  `gorm:"type:int(11);comment:商品id"`
	GoodsTitle string `gorm:"type:varchar(30);comment:商品标题"`
	GoodsImage string `gorm:"type:varchar(30);comment:商品封面"`
	GoodsNum   int64  `gorm:"type:int;default:0;comment:商品数量"`
}

// 订单创建
func (o *Order) Create() error {
	return DB.Create(&o).Error
}

// 订单商品创建
func (og *OrderGood) Create() error {
	return DB.Create(*og).Error
}
